// ============================================================================
//
// Copyright (C) 2006-2007 Dengues
//
// Google Group: http://groups.google.com/group/dengues
// QQ Group: 24885404
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
// ============================================================================
package org.dengues.reports.editor.design.handlers;

import org.dengues.reports.editor.design.parts.ReportElementEditPart;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.Locator;
import org.eclipse.draw2d.MouseEvent;
import org.eclipse.draw2d.MouseMotionListener;
import org.eclipse.draw2d.TreeSearch;
import org.eclipse.gef.DragTracker;
import org.eclipse.gef.GraphicalEditPart;
import org.eclipse.gef.handles.AbstractHandle;

/**
 * The class is the all ReportelemenEditPart base class.
 * 
 * /** Qiang.Zhang.Adolf@gmail.com class global comment. Detailled comment <br/>
 * 
 * $Id: Dengues.epf Qiang.Zhang.Adolf@gmail.com 2008-1-26 qiang.zhang $
 * 
 */
public abstract class AbstractGuideHandle extends AbstractHandle implements MouseMotionListener {

    private boolean isInGuideHandle = false;

    private boolean canDeleteGuide = true;

    public AbstractGuideHandle(GraphicalEditPart owner, Locator loc) {
        super(owner, loc);
        addMouseMotionListener(this);
        getLocator().relocate(this);

    }

    public void mouseEntered(MouseEvent me) {
        // System.out.println( "handle enter" );
        isInGuideHandle = true;
        getReportElementEditPart().addGuideFeedBack();
    }

    public void mouseExited(MouseEvent me) {
        // System.out.println( "handle exit" );
        isInGuideHandle = false;
        getReportElementEditPart().delayRemoveGuideFeedBack();
    }

    public void mouseHover(MouseEvent me) {
        // System.out.println( "handle hover" );
        isInGuideHandle = true;
        getReportElementEditPart().addGuideFeedBack();
    }

    public void mouseMoved(MouseEvent me) {
        // System.out.println( "handle move" );
        isInGuideHandle = true;

        // addGuideFeedBack();
    }

    public void mouseDragged(MouseEvent me) {

    }

    /*
     * (non-Javadoc)
     * 
     * @see org.eclipse.gef.handles.AbstractHandle#createDragTracker()
     */
    @Override
    protected DragTracker createDragTracker() {
        return new org.eclipse.gef.tools.DragEditPartsTracker(getOwner());
    }

    protected ReportElementEditPart getReportElementEditPart() {
        return (ReportElementEditPart) getOwner();
    }

    public boolean isInGuideHandle() {
        return isInGuideHandle;
    }

    /*
     * (non-Javadoc)
     * 
     * @see org.eclipse.draw2d.Figure#findFigureAt(int, int, org.eclipse.draw2d.TreeSearch)
     */
    @Override
    public IFigure findFigureAt(int x, int y, TreeSearch search) {
        return super.findFigureAt(x, y, search);
    }

    /**
     * @return Returns the canDeleteGuide.
     */
    public boolean isCanDeleteGuide() {
        return canDeleteGuide;
    }

    /**
     * @param canDeleteGuide The canDeleteGuide to set.
     */
    public void setCanDeleteGuide(boolean canDeleteGuide) {
        this.canDeleteGuide = canDeleteGuide;
    }
}